<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Set基本用法</title>
</head>

<body>
  <script>
    /*
      1.成员值是唯一的，没有重复值
    */
    // const s = new Set()
    // let num = [2, 3, 4, 5, 4, 3, 2, 1]
    // num.forEach(x => s.add(x))
    // console.log(s)
    // for (const t of s) {
    //   console.log(t)
    // } //5, 4, 3, 2, 1

    /*
      1. 接收数组
      2. 可以对数组进行去重 [...new Set(array)]
    */
    // const set = new Set([1, 2, 3, 4, 5, 4, 3])
    // console.log(set.size)//5
    // console.log([...set])// [1, 2, 3, 4, 5]

    /*
      1.向Set加入值后，不会发生类型转换,类似于'==='恒等于
      2.如果数组中存在多个NaN则显示一个
      3.两个对象总是不相等的
    */
    let set = new Set()
    let a = NaN
    let b = NaN
    set.add(a)
    set.add(b)
    console.log(set) //Set {NaN}
    console.log(set.add({})) //Set {NaN, {}}
    console.log(set.add({})) //Set {NaN, {}, {}}
  </script>
</body>

</html>